using System;
using System.ComponentModel;
using System.Threading;
using FU.Capstones.IMS.Web.Common.InventoryServiceProxy.DataContracts;
using FU.Capstones.IMS.Web.Common.InventoryServiceProxy.EventArgs;
using FU.Capstones.IMS.Web.Common.InventoryServiceProxy.Interfaces;
using FU.Capstones.IMS.Web.Common.InventoryServiceProxy.Respondents;

namespace FU.Capstones.IMS.Web.Common.InventoryServiceProxy.OperationContracts
{
    public partial class InventoryServiceClient
    {

        #region GetContactCollection

        public event EventHandler<CollectionFeedbackCompletedEventArgs<Contact>> GetContactCollectionCompleted;

        [EditorBrowsableAttribute(EditorBrowsableState.Advanced)]
        IAsyncResult IInventoryService.BeginGetContactCollection(bool isShowAll, AsyncCallback callback, object asyncState)
        {
            return Channel.BeginGetContactCollection(isShowAll, callback, asyncState);
        }

        [EditorBrowsableAttribute(EditorBrowsableState.Advanced)]
        CollectionFeedback<Contact> IInventoryService.EndGetContactCollection(IAsyncResult result)
        {
            return Channel.EndGetContactCollection(result);
        }

        private IAsyncResult OnBeginGetContactCollection(object[] inValues, AsyncCallback callback, object asyncState)
        {
            bool isShowAll = (bool)inValues[0];

            return ((IInventoryService)(this)).BeginGetContactCollection(isShowAll, callback, asyncState);
        }

        private object[] OnEndGetContactCollection(IAsyncResult result)
        {
            CollectionFeedback<Contact> retVal = ((IInventoryService)(this)).EndGetContactCollection(result);
            return new object[] { retVal };
        }

        private void OnGetContactCollectionCompleted(object state)
        {
            if ((GetContactCollectionCompleted != null))
            {
                InvokeAsyncCompletedEventArgs e = ((InvokeAsyncCompletedEventArgs)(state));
                GetContactCollectionCompleted(this, new CollectionFeedbackCompletedEventArgs<Contact>(e.Results, e.Error, e.Cancelled, e.UserState));
            }
        }

        public void GetContactCollectionAsync(bool isShowAll)
        {
            GetContactCollectionAsync(isShowAll, null);
        }

        public void GetContactCollectionAsync(bool isShowAll, object userState)
        {
            if ((onBeginGetContactCollectionDelegate == null))
            {
                onBeginGetContactCollectionDelegate = new BeginOperationDelegate(OnBeginGetContactCollection);
            }
            if ((onEndGetContactCollectionDelegate == null))
            {
                onEndGetContactCollectionDelegate = new EndOperationDelegate(OnEndGetContactCollection);
            }
            if ((onGetContactCollectionCompletedDelegate == null))
            {
                onGetContactCollectionCompletedDelegate = new SendOrPostCallback(OnGetContactCollectionCompleted);
            }
            InvokeAsync(onBeginGetContactCollectionDelegate, new object[] {
                    isShowAll}, onEndGetContactCollectionDelegate, onGetContactCollectionCompletedDelegate, userState);
        }

        private BeginOperationDelegate onBeginGetContactCollectionDelegate;

        private EndOperationDelegate onEndGetContactCollectionDelegate;

        private SendOrPostCallback onGetContactCollectionCompletedDelegate;

        private partial class InventoryServiceClientChannel
        {
            public IAsyncResult BeginGetContactCollection(bool isShowAll, AsyncCallback callback, object asyncState)
            {
                object[] _args = new object[1];
                _args[0] = isShowAll;

                IAsyncResult _result = BeginInvoke("GetContactCollection", _args, callback, asyncState);
                return _result;
            }

            public CollectionFeedback<Contact> EndGetContactCollection(IAsyncResult result)
            {
                object[] _args = new object[0];
                CollectionFeedback<Contact> _result = ((CollectionFeedback<Contact>)(EndInvoke("GetContactCollection", _args, result)));
                return _result;
            }
        }

        #endregion
        
        #region GetSingleContact

        public event EventHandler<SingleFeedbackCompletedEventArgs<Contact>> GetSingleContactCompleted;

        [EditorBrowsableAttribute(EditorBrowsableState.Advanced)]
        IAsyncResult IInventoryService.BeginGetSingleContact(int contactID, AsyncCallback callback, object asyncState)
        {
            return Channel.BeginGetSingleContact(contactID, callback, asyncState);
        }

        [EditorBrowsableAttribute(EditorBrowsableState.Advanced)]
        SingleFeedback<Contact> IInventoryService.EndGetSingleContact(IAsyncResult result)
        {
            return Channel.EndGetSingleContact(result);
        }

        private IAsyncResult OnBeginGetSingleContact(object[] inValues, AsyncCallback callback, object asyncState)
        {
            int contactID = (int)inValues[0];

            return ((IInventoryService)(this)).BeginGetSingleContact(contactID, callback, asyncState);
        }

        private object[] OnEndGetSingleContact(IAsyncResult result)
        {
            SingleFeedback<Contact> retVal = ((IInventoryService)(this)).EndGetSingleContact(result);
            return new object[] { retVal };
        }

        private void OnGetSingleContactCompleted(object state)
        {
            if ((GetSingleContactCompleted != null))
            {
                InvokeAsyncCompletedEventArgs e = ((InvokeAsyncCompletedEventArgs)(state));
                GetSingleContactCompleted(this, new SingleFeedbackCompletedEventArgs<Contact>(e.Results, e.Error, e.Cancelled, e.UserState));
            }
        }

        public void GetSingleContactAsync(int contactID)
        {
            GetSingleContactAsync(contactID, null);
        }

        public void GetSingleContactAsync(int contactID, object userState)
        {
            if ((onBeginGetSingleContactDelegate == null))
            {
                onBeginGetSingleContactDelegate = new BeginOperationDelegate(OnBeginGetSingleContact);
            }
            if ((onEndGetSingleContactDelegate == null))
            {
                onEndGetSingleContactDelegate = new EndOperationDelegate(OnEndGetSingleContact);
            }
            if ((onGetSingleContactCompletedDelegate == null))
            {
                onGetSingleContactCompletedDelegate = new SendOrPostCallback(OnGetSingleContactCompleted);
            }
            InvokeAsync(onBeginGetSingleContactDelegate, new object[] {
                                                                                  contactID}, onEndGetSingleContactDelegate, onGetSingleContactCompletedDelegate, userState);
        }

        private BeginOperationDelegate onBeginGetSingleContactDelegate;

        private EndOperationDelegate onEndGetSingleContactDelegate;

        private SendOrPostCallback onGetSingleContactCompletedDelegate;

        private partial class InventoryServiceClientChannel
        {
            public IAsyncResult BeginGetSingleContact(int contactID, AsyncCallback callback, object asyncState)
            {
                object[] _args = new object[1];
                _args[0] = contactID;

                IAsyncResult _result = BeginInvoke("GetSingleContact", _args, callback, asyncState);
                return _result;
            }

            public SingleFeedback<Contact> EndGetSingleContact(IAsyncResult result)
            {
                object[] _args = new object[0];
                SingleFeedback<Contact> _result = ((SingleFeedback<Contact>)(EndInvoke("GetSingleContact", _args, result)));
                return _result;
            }
        }

        #endregion

        #region InsertContact

        public event EventHandler<SingleFeedbackCompletedEventArgs<int>> InsertContactCompleted;

        [EditorBrowsableAttribute(EditorBrowsableState.Advanced)]
        IAsyncResult IInventoryService.BeginInsertContact(Contact data, AsyncCallback callback, object asyncState)
        {
            return Channel.BeginInsertContact(data, callback, asyncState);
        }

        [EditorBrowsableAttribute(EditorBrowsableState.Advanced)]
        SingleFeedback<int> IInventoryService.EndInsertContact(IAsyncResult result)
        {
            return Channel.EndInsertContact(result);
        }

        private IAsyncResult OnBeginInsertContact(object[] inValues, AsyncCallback callback, object asyncState)
        {
            Contact data = (Contact)inValues[0];

            return ((IInventoryService)(this)).BeginInsertContact(data, callback, asyncState);
        }

        private object[] OnEndInsertContact(IAsyncResult result)
        {
            SingleFeedback<int> retVal = ((IInventoryService)(this)).EndInsertContact(result);
            return new object[] { retVal };
        }

        private void OnInsertContactCompleted(object state)
        {
            if ((InsertContactCompleted != null))
            {
                InvokeAsyncCompletedEventArgs e = ((InvokeAsyncCompletedEventArgs)(state));
                InsertContactCompleted(this, new SingleFeedbackCompletedEventArgs<int>(e.Results, e.Error, e.Cancelled, e.UserState));
            }
        }

        public void InsertContactAsync(Contact data)
        {
            InsertContactAsync(data, null);
        }

        public void InsertContactAsync(Contact data, object userState)
        {
            if ((onBeginInsertContactDelegate == null))
            {
                onBeginInsertContactDelegate = new BeginOperationDelegate(OnBeginInsertContact);
            }
            if ((onEndInsertContactDelegate == null))
            {
                onEndInsertContactDelegate = new EndOperationDelegate(OnEndInsertContact);
            }
            if ((onInsertContactCompletedDelegate == null))
            {
                onInsertContactCompletedDelegate = new SendOrPostCallback(OnInsertContactCompleted);
            }
            InvokeAsync(onBeginInsertContactDelegate, new object[] {
                                                                               data}, onEndInsertContactDelegate, onInsertContactCompletedDelegate, userState);
        }

        private BeginOperationDelegate onBeginInsertContactDelegate;

        private EndOperationDelegate onEndInsertContactDelegate;

        private SendOrPostCallback onInsertContactCompletedDelegate;

        private partial class InventoryServiceClientChannel
        {
            public IAsyncResult BeginInsertContact(Contact data, AsyncCallback callback, object asyncState)
            {
                object[] _args = new object[1];
                _args[0] = data;

                IAsyncResult _result = BeginInvoke("InsertContact", _args, callback, asyncState);
                return _result;
            }

            public SingleFeedback<int> EndInsertContact(IAsyncResult result)
            {
                object[] _args = new object[0];
                SingleFeedback<int> _result = ((SingleFeedback<int>)(EndInvoke("InsertContact", _args, result)));
                return _result;
            }
        }

        #endregion

        #region UpdateContact

        public event EventHandler<FeedbackCompletedEventArgs> UpdateContactCompleted;

        [EditorBrowsableAttribute(EditorBrowsableState.Advanced)]
        IAsyncResult IInventoryService.BeginUpdateContact(Contact data, AsyncCallback callback, object asyncState)
        {
            return Channel.BeginUpdateContact(data, callback, asyncState);
        }

        [EditorBrowsableAttribute(EditorBrowsableState.Advanced)]
        Feedback IInventoryService.EndUpdateContact(IAsyncResult result)
        {
            return Channel.EndUpdateContact(result);
        }

        private IAsyncResult OnBeginUpdateContact(object[] inValues, AsyncCallback callback, object asyncState)
        {
            Contact data = (Contact)inValues[0];

            return ((IInventoryService)(this)).BeginUpdateContact(data, callback, asyncState);
        }

        private object[] OnEndUpdateContact(IAsyncResult result)
        {
            Feedback retVal = ((IInventoryService)(this)).EndUpdateContact(result);
            return new object[] { retVal };
        }

        private void OnUpdateContactCompleted(object state)
        {
            if ((UpdateContactCompleted != null))
            {
                InvokeAsyncCompletedEventArgs e = ((InvokeAsyncCompletedEventArgs)(state));
                UpdateContactCompleted(this, new FeedbackCompletedEventArgs(e.Results, e.Error, e.Cancelled, e.UserState));
            }
        }

        public void UpdateContactAsync(Contact data)
        {
            UpdateContactAsync(data, null);
        }

        public void UpdateContactAsync(Contact data, object userState)
        {
            if ((onBeginUpdateContactDelegate == null))
            {
                onBeginUpdateContactDelegate = new BeginOperationDelegate(OnBeginUpdateContact);
            }
            if ((onEndUpdateContactDelegate == null))
            {
                onEndUpdateContactDelegate = new EndOperationDelegate(OnEndUpdateContact);
            }
            if ((onUpdateContactCompletedDelegate == null))
            {
                onUpdateContactCompletedDelegate = new SendOrPostCallback(OnUpdateContactCompleted);
            }
            InvokeAsync(onBeginUpdateContactDelegate, new object[] {
                                                                               data}, onEndUpdateContactDelegate, onUpdateContactCompletedDelegate, userState);
        }

        private BeginOperationDelegate onBeginUpdateContactDelegate;

        private EndOperationDelegate onEndUpdateContactDelegate;

        private SendOrPostCallback onUpdateContactCompletedDelegate;

        private partial class InventoryServiceClientChannel
        {
            public IAsyncResult BeginUpdateContact(Contact data, AsyncCallback callback, object asyncState)
            {
                object[] _args = new object[1];
                _args[0] = data;

                IAsyncResult _result = BeginInvoke("UpdateContact", _args, callback, asyncState);
                return _result;
            }

            public Feedback EndUpdateContact(IAsyncResult result)
            {
                object[] _args = new object[0];
                Feedback _result = ((Feedback)(EndInvoke("UpdateContact", _args, result)));
                return _result;
            }
        }

        #endregion

        #region DeleteContact

        public event EventHandler<FeedbackCompletedEventArgs> DeleteContactCompleted;

        [EditorBrowsableAttribute(EditorBrowsableState.Advanced)]
        IAsyncResult IInventoryService.BeginDeleteContact(int data, AsyncCallback callback, object asyncState)
        {
            return Channel.BeginDeleteContact(data, callback, asyncState);
        }

        [EditorBrowsableAttribute(EditorBrowsableState.Advanced)]
        Feedback IInventoryService.EndDeleteContact(IAsyncResult result)
        {
            return Channel.EndDeleteContact(result);
        }

        private IAsyncResult OnBeginDeleteContact(object[] inValues, AsyncCallback callback, object asyncState)
        {
            int data = (int)inValues[0];

            return ((IInventoryService)(this)).BeginDeleteContact(data, callback, asyncState);
        }

        private object[] OnEndDeleteContact(IAsyncResult result)
        {
            Feedback retVal = ((IInventoryService)(this)).EndDeleteContact(result);
            return new object[] { retVal };
        }

        private void OnDeleteContactCompleted(object state)
        {
            if ((DeleteContactCompleted != null))
            {
                InvokeAsyncCompletedEventArgs e = ((InvokeAsyncCompletedEventArgs)(state));
                DeleteContactCompleted(this, new FeedbackCompletedEventArgs(e.Results, e.Error, e.Cancelled, e.UserState));
            }
        }

        public void DeleteContactAsync(int objID)
        {
            DeleteContactAsync(objID, null);
        }

        public void DeleteContactAsync(int data, object userState)
        {
            if ((onBeginDeleteContactDelegate == null))
            {
                onBeginDeleteContactDelegate = new BeginOperationDelegate(OnBeginDeleteContact);
            }
            if ((onEndDeleteContactDelegate == null))
            {
                onEndDeleteContactDelegate = new EndOperationDelegate(OnEndDeleteContact);
            }
            if ((onDeleteContactCompletedDelegate == null))
            {
                onDeleteContactCompletedDelegate = new SendOrPostCallback(OnDeleteContactCompleted);
            }
            InvokeAsync(onBeginDeleteContactDelegate, new object[] {
                                                                               data}, onEndDeleteContactDelegate, onDeleteContactCompletedDelegate, userState);
        }

        private BeginOperationDelegate onBeginDeleteContactDelegate;

        private EndOperationDelegate onEndDeleteContactDelegate;

        private SendOrPostCallback onDeleteContactCompletedDelegate;

        private partial class InventoryServiceClientChannel
        {
            public IAsyncResult BeginDeleteContact(int data, AsyncCallback callback, object asyncState)
            {
                object[] _args = new object[1];
                _args[0] = data;

                IAsyncResult _result = BeginInvoke("DeleteContact", _args, callback, asyncState);
                return _result;
            }

            public Feedback EndDeleteContact(IAsyncResult result)
            {
                object[] _args = new object[0];
                Feedback _result = ((Feedback)(EndInvoke("DeleteContact", _args, result)));
                return _result;
            }
        }

        #endregion

        #region SearchContact

        public event EventHandler<CollectionFeedbackCompletedEventArgs<Contact>> SearchContactCompleted;

        [EditorBrowsableAttribute(EditorBrowsableState.Advanced)]
        IAsyncResult IInventoryService.BeginSearchContact(Contact criteria, AsyncCallback callback, object asyncState)
        {
            return Channel.BeginSearchContact(criteria, callback, asyncState);
        }

        [EditorBrowsableAttribute(EditorBrowsableState.Advanced)]
        CollectionFeedback<Contact> IInventoryService.EndSearchContact(IAsyncResult result)
        {
            return Channel.EndSearchContact(result);
        }

        private IAsyncResult OnBeginSearchContact(object[] inValues, AsyncCallback callback, object asyncState)
        {
            Contact criteria = (Contact)inValues[0];

            return ((IInventoryService)(this)).BeginSearchContact(criteria, callback, asyncState);
        }

        private object[] OnEndSearchContact(IAsyncResult result)
        {
            CollectionFeedback<Contact> retVal = ((IInventoryService)(this)).EndSearchContact(result);
            return new object[] { retVal };
        }

        private void OnSearchContactCompleted(object state)
        {
            if ((SearchContactCompleted != null))
            {
                InvokeAsyncCompletedEventArgs e = ((InvokeAsyncCompletedEventArgs)(state));
                SearchContactCompleted(this, new CollectionFeedbackCompletedEventArgs<Contact>(e.Results, e.Error, e.Cancelled, e.UserState));
            }
        }

        public void SearchContactAsync(Contact criteria)
        {
            SearchContactAsync(criteria, null);
        }

        public void SearchContactAsync(Contact criteria, object userState)
        {
            if ((onBeginSearchContactDelegate == null))
            {
                onBeginSearchContactDelegate = new BeginOperationDelegate(OnBeginSearchContact);
            }
            if ((onEndSearchContactDelegate == null))
            {
                onEndSearchContactDelegate = new EndOperationDelegate(OnEndSearchContact);
            }
            if ((onSearchContactCompletedDelegate == null))
            {
                onSearchContactCompletedDelegate = new SendOrPostCallback(OnSearchContactCompleted);
            }
            InvokeAsync(onBeginSearchContactDelegate, new object[] {
                                                                               criteria}, onEndSearchContactDelegate, onSearchContactCompletedDelegate, userState);
        }

        private BeginOperationDelegate onBeginSearchContactDelegate;

        private EndOperationDelegate onEndSearchContactDelegate;

        private SendOrPostCallback onSearchContactCompletedDelegate;

        private partial class InventoryServiceClientChannel
        {
            public IAsyncResult BeginSearchContact(Contact criteria, AsyncCallback callback, object asyncState)
            {
                object[] _args = new object[1];
                _args[0] = criteria;

                IAsyncResult _result = BeginInvoke("SearchContact", _args, callback, asyncState);
                return _result;
            }

            public CollectionFeedback<Contact> EndSearchContact(IAsyncResult result)
            {
                object[] _args = new object[0];
                CollectionFeedback<Contact> _result = ((CollectionFeedback<Contact>)(EndInvoke("SearchContact", _args, result)));
                return _result;
            }
        }

        #endregion

        #region UndoDeleteContact

        public event EventHandler<FeedbackCompletedEventArgs> UndoDeleteContactCompleted;

        [EditorBrowsableAttribute(EditorBrowsableState.Advanced)]
        IAsyncResult IInventoryService.BeginUndoDeleteContact(int objID, AsyncCallback callback, object asyncState)
        {
            return Channel.BeginUndoDeleteContact(objID, callback, asyncState);
        }

        [EditorBrowsableAttribute(EditorBrowsableState.Advanced)]
        Feedback IInventoryService.EndUndoDeleteContact(IAsyncResult result)
        {
            return Channel.EndUndoDeleteContact(result);
        }

        private IAsyncResult OnBeginUndoDeleteContact(object[] inValues, AsyncCallback callback, object asyncState)
        {
            int objID = (int)inValues[0];

            return ((IInventoryService)(this)).BeginUndoDeleteContact(objID, callback, asyncState);
        }

        private object[] OnEndUndoDeleteContact(IAsyncResult result)
        {
            Feedback retVal = ((IInventoryService)(this)).EndUndoDeleteContact(result);
            return new object[] { retVal };
        }

        private void OnUndoDeleteContactCompleted(object state)
        {
            if ((UndoDeleteContactCompleted != null))
            {
                InvokeAsyncCompletedEventArgs e = ((InvokeAsyncCompletedEventArgs)(state));
                UndoDeleteContactCompleted(this, new FeedbackCompletedEventArgs(e.Results, e.Error, e.Cancelled, e.UserState));
            }
        }

        public void UndoDeleteContactAsync(int objID)
        {
            UndoDeleteContactAsync(objID, null);
        }

        public void UndoDeleteContactAsync(int objID, object userState)
        {
            if ((onBeginUndoDeleteContactDelegate == null))
            {
                onBeginUndoDeleteContactDelegate = new BeginOperationDelegate(OnBeginUndoDeleteContact);
            }
            if ((onEndUndoDeleteContactDelegate == null))
            {
                onEndUndoDeleteContactDelegate = new EndOperationDelegate(OnEndUndoDeleteContact);
            }
            if ((onUndoDeleteContactCompletedDelegate == null))
            {
                onUndoDeleteContactCompletedDelegate = new SendOrPostCallback(OnUndoDeleteContactCompleted);
            }
            InvokeAsync(onBeginUndoDeleteContactDelegate, new object[] {
                    objID}, onEndUndoDeleteContactDelegate, onUndoDeleteContactCompletedDelegate, userState);
        }

        private BeginOperationDelegate onBeginUndoDeleteContactDelegate;

        private EndOperationDelegate onEndUndoDeleteContactDelegate;

        private SendOrPostCallback onUndoDeleteContactCompletedDelegate;

        private partial class InventoryServiceClientChannel
        {
            public IAsyncResult BeginUndoDeleteContact(int objID, AsyncCallback callback, object asyncState)
            {
                object[] _args = new object[1];
                _args[0] = objID;

                IAsyncResult _result = BeginInvoke("UndoDeleteContact", _args, callback, asyncState);
                return _result;
            }

            public Feedback EndUndoDeleteContact(IAsyncResult result)
            {
                object[] _args = new object[0];
                Feedback _result = ((Feedback)(EndInvoke("UndoDeleteContact", _args, result)));
                return _result;
            }
        }

        #endregion
        

    }
}